package com.zfdang.touchhelper.tool;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

import java.util.Set;


/**
 * @author ly-dengpw
 */
public class LyPreferenceTool {

    public static LyPreferenceTool getInstance() {
        return LyPreferenceTool.SingletonFactory.INSTANCE;
    }

    private static class SingletonFactory {
        private static final LyPreferenceTool INSTANCE = new LyPreferenceTool();
    }


    private SharedPreferences mSharedPreferences = null;
    public void init(Context context) {
        if (null == mSharedPreferences) {
            mSharedPreferences = context.getSharedPreferences("TouchHelper_Config", Context.MODE_PRIVATE);
        }
    }


    public void putBoolean(String key, boolean value) {
        Editor mEditor = mSharedPreferences.edit();
        mEditor.putBoolean(key, value);
        mEditor.apply();
    }

    public void putInt(String key, int value) {
        Editor mEditor = mSharedPreferences.edit();
        mEditor.putInt(key, value);
        mEditor.apply();
    }

    public void putString(String key, String value) {
        Editor mEditor = mSharedPreferences.edit();
        mEditor.putString(key, value);
        mEditor.apply();
    }

    public void putStringSet(String key,  Set<String> values) {
        Editor mEditor = mSharedPreferences.edit();
        mEditor.putStringSet(key, values);
        mEditor.apply();
    }


    public boolean getBoolean(String key, boolean failValue) {
        return mSharedPreferences.getBoolean(key, failValue);
    }

    public String getString(String key, String defValue) {
        return mSharedPreferences.getString(key, defValue);
    }

    public int getInt(String key, int defValue) {
        return mSharedPreferences.getInt(key, defValue);
    }

    public Set<String> getStringSet(String key, Set<String> defValue ) {
        return mSharedPreferences.getStringSet(key, defValue);
    }


}
